package com.ruoyi.admin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.admin.domain.PjFile;
import com.ruoyi.admin.service.IPjFileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文件Controller
 * 
 * @author kzc
 * @date 2024-03-17
 */
@RestController
@RequestMapping("/admin/file")
public class PjFileController extends BaseController
{
    @Autowired
    private IPjFileService pjFileService;

    /**
     * 查询文件列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PjFile pjFile)
    {
        startPage();
        List<PjFile> list = pjFileService.selectPjFileList(pjFile);
        return getDataTable(list);
    }

    /**
     * 导出文件列表
     */
    @Log(title = "文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PjFile pjFile)
    {
        List<PjFile> list = pjFileService.selectPjFileList(pjFile);
        ExcelUtil<PjFile> util = new ExcelUtil<PjFile>(PjFile.class);
        util.exportExcel(response, list, "文件数据");
    }

    /**
     * 获取文件详细信息
     */
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Integer fileId)
    {
        return success(pjFileService.selectPjFileByFileId(fileId));
    }

    /**
     * 新增文件
     */
    @Log(title = "文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PjFile pjFile)
    {
        return toAjax(pjFileService.insertPjFile(pjFile));
    }

    /**
     * 修改文件
     */
    @Log(title = "文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PjFile pjFile)
    {
        return toAjax(pjFileService.updatePjFile(pjFile));
    }

    /**
     * 删除文件
     */
    @Log(title = "文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable Integer[] fileIds)
    {
        return toAjax(pjFileService.deletePjFileByFileIds(fileIds));
    }
}
